﻿using System;
using System.Diagnostics;
using System.Windows.Forms;
using mki.Backup.GUI.Properties;
using mki.Backup.Helper;

namespace mki.Backup.GUI.Helper
{
	/// <summary>
	/// Messagebox handler
	/// </summary>
	public class MessageBoxHandler
	{
		#region Methods (19)

		// Public Static Methods (18) 

		/// <summary>
		/// Shows the error message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="param">The param.</param>
		/// <returns>returns a object of type DialogResult</returns>
		public static DialogResult ShowErrorMessageBox(String message, params Object[] param)
		{
			return showMessageBox(message, Resources.ErrorMessageBoxDefaultTitle, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, param);
		}

		/// <summary>
		/// Shows the error message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="buttons">The buttons.</param>
		/// <param name="param">The param.</param>
		/// <returns>returns a object of type DialogResult</returns>
		public static DialogResult ShowErrorMessageBox(String message, MessageBoxButtons buttons, params Object[] param)
		{
			return showMessageBox(message, Resources.ErrorMessageBoxDefaultTitle, buttons, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, param);
		}

		/// <summary>
		/// Shows the error message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="caption">The caption.</param>
		/// <param name="buttons">The buttons.</param>
		/// <param name="defaultButton">The default button.</param>
		/// <param name="param">The param.</param>
		/// <returns>returns a object of type DialogResult</returns>
		public static DialogResult ShowErrorMessageBox(String message, String caption, MessageBoxButtons buttons, MessageBoxDefaultButton defaultButton, params Object[] param)
		{
			return showMessageBox(message, !String.IsNullOrWhiteSpace(caption) ? caption : Resources.ErrorMessageBoxDefaultTitle, buttons, MessageBoxIcon.Error, defaultButton, param);
		}

		/// <summary>
		/// Shows the exclamation message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="param">The param.</param>
		/// <returns>returns a object of type DialogResult</returns>
		public static DialogResult ShowExclamationMessageBox(String message, params Object[] param)
		{
			return showMessageBox(message, Resources.InfoMessageBoxDefaultTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, param);
		}

		/// <summary>
		/// Shows the exclamation message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="buttons">The buttons.</param>
		/// <param name="param">The param.</param>
		/// <returns>returns a object of type DialogResult</returns>
		public static DialogResult ShowExclamationMessageBox(String message, MessageBoxButtons buttons, params Object[] param)
		{
			return showMessageBox(message, Resources.InfoMessageBoxDefaultTitle, buttons, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, param);
		}

		/// <summary>
		/// Shows the exclamation message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="buttons">The buttons.</param>
		/// <param name="defaultButton">The default button.</param>
		/// <param name="param">The param.</param>
		/// <returns>returns a object of type DialogResult</returns>
		public static DialogResult ShowExclamationMessageBox(String message, MessageBoxButtons buttons, MessageBoxDefaultButton defaultButton = MessageBoxDefaultButton.Button1, params Object[] param)
		{
			return showMessageBox(message, Resources.InfoMessageBoxDefaultTitle, buttons, MessageBoxIcon.Exclamation, defaultButton, param);
		}

		/// <summary>
		/// Shows the exclamation message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="caption">The caption.</param>
		/// <param name="buttons">The buttons.</param>
		/// <param name="defaultButton">The default button.</param>
		/// <param name="param">The param.</param>
		/// <returns>returns a object of type DialogResult</returns>
		public static DialogResult ShowExclamationMessageBox(String message, String caption, MessageBoxButtons buttons, MessageBoxDefaultButton defaultButton, params Object[] param)
		{
			return showMessageBox(message, !String.IsNullOrWhiteSpace(caption) ? caption : Resources.InfoMessageBoxDefaultTitle, buttons, MessageBoxIcon.Exclamation, defaultButton, param);
		}

		/// <summary>
		/// Shows the info message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="param">The param.</param>
		/// <returns>returns a object of type DialogResult</returns>
		public static DialogResult ShowInfoMessageBox(String message, params Object[] param)
		{
			return showMessageBox(message, Resources.InfoMessageBoxDefaultTitle, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, param);
		}

		/// <summary>
		/// Shows the info message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="buttons">The buttons.</param>
		/// <param name="param">The param.</param>
		/// <returns>returns a object of type DialogResult</returns>
		public static DialogResult ShowInfoMessageBox(String message, MessageBoxButtons buttons, params Object[] param)
		{
			return showMessageBox(message, Resources.InfoMessageBoxDefaultTitle, buttons, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, param);
		}

		/// <summary>
		/// Shows the info message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="buttons">The buttons.</param>
		/// <param name="defaultButton">The default button.</param>
		/// <param name="param">The param.</param>
		/// <returns>returns a object of type DialogResult</returns>
		public static DialogResult ShowInfoMessageBox(String message, MessageBoxButtons buttons, MessageBoxDefaultButton defaultButton, params Object[] param)
		{
			return showMessageBox(message, Resources.InfoMessageBoxDefaultTitle, buttons, MessageBoxIcon.Information, defaultButton, param);
		}

		/// <summary>
		/// Shows the info message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="caption">The caption.</param>
		/// <param name="buttons">The buttons.</param>
		/// <param name="defaultButton">The default button.</param>
		/// <param name="param">The param.</param>
		/// <returns>returns a object of type DialogResult</returns>
		public static DialogResult ShowInfoMessageBox(String message, String caption, MessageBoxButtons buttons, MessageBoxDefaultButton defaultButton, params Object[] param)
		{
			return showMessageBox(message, !String.IsNullOrWhiteSpace(caption) ? caption : Resources.InfoMessageBoxDefaultTitle, buttons, MessageBoxIcon.Information, defaultButton, param);
		}

		/// <summary>
		/// Shows the question message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="caption">The caption.</param>
		/// <param name="param">The param.</param>
		/// <returns>returns a object of type DialogResult</returns>
		public static DialogResult ShowQuestionMessageBox(String message, String caption, params Object[] param)
		{
			return showMessageBox(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, param);
		}

		/// <summary>
		/// Shows the question message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="caption">The caption.</param>
		/// <param name="buttons">The buttons.</param>
		/// <param name="param">The param.</param>
		/// <returns>returns a object of type DialogResult</returns>
		public static DialogResult ShowQuestionMessageBox(String message, String caption, MessageBoxButtons buttons, params Object[] param)
		{
			return showMessageBox(message, caption, buttons, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, param);
		}

		/// <summary>
		/// Shows the question message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="caption">The caption.</param>
		/// <param name="buttons">The buttons.</param>
		/// <param name="defaultButton">The default button.</param>
		/// <param name="param">The param.</param>
		/// <returns>returns a object of type DialogResult</returns>
		public static DialogResult ShowQuestionMessageBox(String message, String caption, MessageBoxButtons buttons, MessageBoxDefaultButton defaultButton, params Object[] param)
		{
			return showMessageBox(message, caption, buttons, MessageBoxIcon.Question, defaultButton, param);
		}

		/// <summary>
		/// Shows the warning message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="param">The param.</param>
		/// <returns>returns a object of type DialogResult</returns>
		public static DialogResult ShowWarningMessageBox(String message, params Object[] param)
		{
			return showMessageBox(message, Resources.WarningMessageBoxDefaultTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, param);
		}

		/// <summary>
		/// Shows the warning message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="buttons">The buttons.</param>
		/// <param name="param">The param.</param>
		/// <returns>returns a object of type DialogResult</returns>
		public static DialogResult ShowWarningMessageBox(String message, MessageBoxButtons buttons, params Object[] param)
		{
			return showMessageBox(message, Resources.WarningMessageBoxDefaultTitle, buttons, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, param);
		}

		/// <summary>
		/// Shows the warning message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="buttons">The buttons.</param>
		/// <param name="defaultButton">The default button.</param>
		/// <param name="param">The param.</param>
		/// <returns>returns a object of type DialogResult</returns>
		public static DialogResult ShowWarningMessageBox(String message, MessageBoxButtons buttons, MessageBoxDefaultButton defaultButton, params Object[] param)
		{
			return showMessageBox(message, Resources.WarningMessageBoxDefaultTitle, buttons, MessageBoxIcon.Warning, defaultButton, param);
		}

		/// <summary>
		/// Shows the warning message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="caption">The caption.</param>
		/// <param name="buttons">The buttons.</param>
		/// <param name="defaultButton">The default button.</param>
		/// <param name="param">The param.</param>
		/// <returns>returns a object of type DialogResult</returns>
		public static DialogResult ShowWarningMessageBox(String message, String caption, MessageBoxButtons buttons, MessageBoxDefaultButton defaultButton, params Object[] param)
		{
			return showMessageBox(message, !String.IsNullOrWhiteSpace(caption) ? caption : Resources.WarningMessageBoxDefaultTitle, buttons, MessageBoxIcon.Warning, defaultButton, param);
		}
		// Private Static Methods (1) 

		/// <summary>
		/// Shows the message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="caption">The captaion.</param>
		/// <param name="buttons">The buttons.</param>
		/// <param name="icon">The icon.</param>
		/// <param name="defaultButton">The default button.</param>
		/// <param name="param">The param.</param>
		/// <returns>returns a object of type DialogResult</returns>
		private static DialogResult showMessageBox(String message, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, params Object[] param)
		{
			// need to insert params to message?
			if (param != null) { message = String.Format(message, param); }

			// show message box
			var result = MessageBox.Show(message, caption, buttons, icon, defaultButton);

			try
			{	// do logging
				Logging.WriteVerbose("Users response to '{0}' was '{1}'", message.Trim(), result);
			}
			catch
			{
				if (Debugger.IsAttached) { Console.WriteLine(@"Error while logging MessageBoxHandler.DialogResult"); }
			}

			return result;
		}

		#endregion Methods
	}
}